<template>
  <div id="app">
    <ul>
      <!-- v-for遍历数组 -->
      <li v-for="(item,index) in arr" :key="index">
        <span>{{item}}</span>
        <button @click="del(index)">删除</button>
      </li>
    </ul>
    <button @click="add">生成</button>
  </div>
</template>

<script>
export default {

  data() {
    return {
      arr: [1, 5, 3],
    };
  },
  methods: {
    // 新增随机数字
    add(){
      this.arr.push(parseInt(Math.random()*10))

    },
    del(num){
      //点击删除按钮,删除对应的li和值
      this.arr.splice(num,1)
    }
  }
}
</script>